home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / createFontPopup.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.9 KB  |  181 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  August 14, 1996
  22. //  Author:         ms
  23. //
  24. //  Description:
  25. //      Make a popup for all the fonts available
  26. //
  27. //  Input Arguments:
  28. //      The layout.
  29. //
  30. //  Return Value:
  31. //      None.
  32. //
  33.  
  34. proc string fontTypeName( string $fName )
  35. {
  36.     string $name = "";
  37.     string $all[];
  38.     tokenize( $fName, "-", $all );
  39.     if( size($all) > 1 ) {
  40.         $name = $all[0];
  41.     }
  42.     return $name;
  43. }
  44.  
  45.  
  46. global proc doFontDialog ( string $tabLayout )
  47. {
  48.     if (`exists Win32Init`)
  49.     {
  50.         string $fName = `fontDialog`;
  51.         if ($fName == "") return;
  52.         resetFontFieldText $tabLayout $fName;    
  53.     }
  54. }
  55.  
  56. global proc createFontPopup( string $tabLayout, string $fontPopup,
  57.                              string $command, string $extraArg )
  58. {
  59.     int $maxLinesPerScreen = 36;
  60.     string $listOfFonts[] = `fontDialog -FontList`;
  61.  
  62.     int $n = size($listOfFonts);
  63.  
  64.     popupMenu -e -dai $fontPopup;
  65.     setParent -menu $fontPopup;
  66.  
  67.     string $itemName, $fontName;
  68.     if ( $extraArg == "NULL" ) $extraArg = "";
  69.     string $dowhat = ( $command + " " + $extraArg + " " +
  70.                        "\"" + $tabLayout + "\" " );
  71.  
  72.     string $currentFontType, $thisFontType, $nextFontType;
  73.     int $i, $cntr, $subs, $moreSubs, $lineCntr;
  74.  
  75.     // Now make the menu popup - go hierarchical for the same type.
  76.     $currentFontType = "";
  77.     $moreSubs = 0;
  78.     $lineCntr = 0;
  79.     $cntr = 0;
  80.     $subs = 0;
  81.  
  82.     // GG - this should be first, because Marking Menus only support 30 items.
  83.     if (`exists Win32Init`) {
  84.         menuItem -c ("doFontDialog " + "\"" + $tabLayout + "\";")
  85.           -l "Select...";
  86.     }
  87.     else {
  88.         // Go through each item in the list:
  89.         for( $i=0; $i<$n; $i+=1 ) {
  90.             $itemName = "SEFM" + string($i);
  91.             $fontName = $listOfFonts[$i];
  92.  
  93.             if (`exists Win32Init`) {
  94.                 menuItem -c ($dowhat + "\"" + $fontName + "\";")
  95.                   -l $fontName $itemName;
  96.             }
  97.             else {
  98.                 // Find out the font type; this is either the string
  99.                 // before the "-" or "" if the font name has no "-"
  100.                 $thisFontType = fontTypeName( $fontName );
  101.  
  102.                 // Find the font type of the next item, if there is one:
  103.                 $nextFontType = "";
  104.                 if( $i+1 < $n ) {
  105.                     $nextFontType = fontTypeName( $listOfFonts[$i+1] );
  106.                 }
  107.  
  108.                 // If we have something like "Courier" followed by
  109.                 // "Courier-Bold" we have to recognize they are in the
  110.                 // same group.
  111.                 if( ($thisFontType == "") && ($nextFontType == $fontName) ) {
  112.                     $thisFontType = $nextFontType;
  113.                 }
  114.  
  115.                 // If we are already processing this font type, we'll just
  116.                 // add the menu item to the list.
  117.                 if( $thisFontType == $currentFontType ) {
  118.                     if( 0 == $subs ) {
  119.                         $lineCntr += 1;
  120.                         if( $lineCntr > $maxLinesPerScreen ) {
  121.                             $moreSubs += 1;
  122.                             menuItem -l "More..."
  123.                               -subMenu true
  124.                               ("SESMM" + string($moreSubs));
  125.                             $lineCntr = 0;
  126.                         }
  127.                     }
  128.                     menuItem -c ($dowhat + "\"" + $fontName + "\";")
  129.                       -l $fontName $itemName;
  130.                 }
  131.                 else {
  132.                     // In this case, the font type is different.  So, we
  133.                     // have to close down the previous sub menu first:
  134.  
  135.                     if( $subs > 0 ) {
  136.                         $subs -= 1;
  137.                         setParent -menu ..;
  138.                     }
  139.  
  140.                     // How menu total screen lines are we taking:
  141.                     $lineCntr += 1;
  142.                     if( $lineCntr > $maxLinesPerScreen ) {
  143.                         $moreSubs += 1;
  144.                         menuItem -l "More..."
  145.                           -subMenu true
  146.                           ("SESMM" + string($moreSubs));
  147.                         $lineCntr = 0;
  148.                     }
  149.  
  150.                     // If this is the first item of a font type with multiple
  151.                     // items, we better start a new sub item.
  152.                     if( ($thisFontType != "") &&
  153.                         ($thisFontType == $nextFontType)) {
  154.                         menuItem -l $thisFontType
  155.                           -subMenu true
  156.                           ("SESM" + string($cntr));
  157.                         $cntr += 1;
  158.                         $subs += 1;
  159.                     }
  160.  
  161.                     // Add the actual menu item; this is either under the above
  162.                     // sub menu item, or just on its own.
  163.                     menuItem -c ($dowhat + "\"" + $fontName + "\";")
  164.                       -l $fontName $itemName;
  165.                     $currentFontType = $thisFontType;
  166.                 }
  167.             }
  168.         }
  169.  
  170.         for( $i=0; $i<$moreSubs; $i+=1 ) {
  171.             setParent -menu ..;
  172.         }
  173.  
  174.         if( $currentFontType != "" ) {
  175.             $subs -= 1;
  176.             setParent -menu ..;
  177.         }
  178.     }
  179. }
  180.  
  181.